var watchElements = "input,select,textarea";

/**
 * 폼 변경 감지를 위한 원본값을 hash에 저장한다.
 * @param form 폼id selector
 * @param ignore 변경감지 제외 컨트롤 selector
 */
var watchChanged = function(form, ignoreElements) {
	try{
		if($(form).length == 0) {
			throw new Error("Invalid form selector");
		}
		// 원본데이터 저장
		if(ignoreElements) {
			$(form + " " + ignoreElements).each(function() {
				$(this).addClass("ignore-changed");
			});	
		}
		console.log("------------- call watchChanged serialize -----------------");
		var data = $(form + " "+watchElements).not(".ignore-changed").serialize();
		console.log(data);
		
		
	    $(form).data("hash", data);
		
	} catch(e) {
		alert("Javascript Error: " + e.message);
	} finally{}
}; 

/**
 * 폼 변경여부를 리턴한다.
 * @param form 폼id selector
 */
/*var isChanged = function (form) {
	var changed = false;
	try{
		if($(form).length == 0) {
			throw new Error("Invalid form selector");
		}    

	    console.log("------------- call isChanged serialize -----------------");
	    var data = $(form + " "+watchElements).not(".ignore-changed").serialize();
	    console.log(data);
	    
	    if ($(form).data("hash") !== data) {
	        changed = true;
	        return changed;
	    }
	    return changed;
	} catch(e) {
		alert("Javascript Error: " + e.message);
	} finally{}	    
};*/

/**
 * 폼 변경여부를 리턴한다.
 * @param form 폼id selector
 * @param objcallback callback object
 */
var isChanged = function (form, objcallback) {
	var changed = false;
	try{
		if($(form).length == 0) {
			throw new Error("Invalid form selector");
		}    
		
		console.log("------------- call isChanged serialize -----------------");
		var data = $(form + " "+watchElements).not(".ignore-changed").serialize();
		console.log(data);
		
		if ($(form).data("hash") !== data) {
			changed = true;
		}	
		
		changed? objcallback["changed"]():objcallback["unchanged"]();
		
	} catch(e) {
		alert("Javascript Error: " + e.message);
	} finally{}	    
};


/**
 * 코드리스트를 select박스에 셋업한다.
 * @param selector select컨트롤 selector
 */
var respCodeSelect = function(selector, data, state) {
    console.log("--- callback success ---");
    console.log("data: " + data);
    console.log("state: " + state);
    
    var cdNamCol = commonCdNmI18n(); // i18n다국어 컬럼 적용
    $.each(data, function(index, element) {
        $(selector).append("<option value='"+element.CD_DATA+"' "+(index==0? "selected":"")+" >" + 
            eval("element." + cdNamCol) + 
            "</option>");
    }); 
}; 
